//
//  FriendHobbyCell.m
//  SportSocial
//
//  Created by hanfangyu on 15/2/11.
//  Copyright (c) 2015年 yull. All rights reserved.
//

#import "FriendHobbyCell.h"
#import "ImageCollectionCell.h"

@implementation FriendHobbyCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        flowLayout.minimumInteritemSpacing = 10;
        flowLayout.minimumLineSpacing = 10;
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        self.hobbyCollectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
        self.hobbyCollectionView.delegate = self;
        self.hobbyCollectionView.dataSource = self;
        self.hobbyCollectionView.backgroundColor = [UIColor whiteColor];
        self.hobbyCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
        self.hobbyCollectionView.showsHorizontalScrollIndicator = NO;
        [self.hobbyCollectionView registerClass:[ImageCollectionCell class] forCellWithReuseIdentifier:@"ImageCell"];
        [self.contentView addSubview:self.hobbyCollectionView];
    }
    return self;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.userModel.hobby_sport.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ImageCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ImageCell" forIndexPath:indexPath];
    
    NSString *imageName = [self.userModel.hobby_sport objectAtIndex:indexPath.row];
    
    if (imageName.length) {
        cell.imageView.image = [UIImage imageNamed:imageName];
    }
    
    return cell;
}

- (void)drawCellWithUserModel:(UserModel *)userModel
{
    self.userModel = userModel;
    
    [self.hobbyCollectionView reloadData];
}
@end
